﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class form_topic : System.Web.UI.UserControl
{
    Topic_BU tp_BU = new Topic_BU();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadTopicById();
        }
    }

    public void loadTopicById()
    {
       
        int topic_id=0;
        if (Request.QueryString["path"] != "")
        {
           topic_id = Convert.ToInt32(Request.QueryString["path"]);
            DataTable dt = tp_BU.getTopicByID(topic_id);
            foreach (DataRow dr in dt.Rows)
            {
                txtTopicName.Text = dr["topic_name"].ToString();
                txtDes.Text = dr["topic_des"].ToString();
                lbDate.Text = dr["date_added"].ToString();
            }
            
        }
       
    }
    protected void OK_Click(object sender, ImageClickEventArgs e)
    {
        int topic_id = 0;
        string topicName = txtTopicName.Text;
        string topicDes = txtDes.Text;
        if (Request.QueryString["path"] != "" && Request.QueryString["path"] != null)
        {
            topic_id = Convert.ToInt32(Request.QueryString["path"]);
            tp_BU.Update_Topic(topic_id, topicName, topicDes);
            Response.Redirect("default.aspx?action=Topic");
        }
        else{
            tp_BU.Update_Topic(topic_id, txtTopicName.Text, txtDes.Text);
            Response.Redirect("default.aspx?action=Topic");
        }
    }
    protected void Cancle_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("default.aspx?action=Topic");
    }
}